# Contributor: Rasmus Thomsen <oss@cogitri.dev>
# Contributor: Carlo Landmeter <clandmeter@alpinelinux.org>
# Maintainer: Rasmus Thomsen <oss@cogitri.dev>
pkgname=transmission
pkgver=3.00
pkgrel=6
pkgdesc="Lightweight GTK BitTorrent client"
url="https://transmissionbt.com/"
install="transmission-daemon.pre-install transmission-daemon.post-upgrade"
arch="all"
license="GPL-2.0-or-later AND MIT"
pkgusers="transmission"
pkggroups="transmission"
makedepends="cmake bsd-compat-headers curl-dev dbus-glib-dev samurai
	gtk+3.0-dev intltool libevent-dev libnotify-dev openssl1.1-compat-dev tar"
options="!check" # no tests
source="https://github.com/transmission/transmission-releases/raw/master/transmission-$pkgver.tar.xz
	transmission-daemon.initd
	transmission-daemon.confd
	transmission-daemon.logrotate
	disable-missing-lang.patch
	fix-gettext-sigsegv.patch
	"
subpackages="$pkgname-cli $pkgname-daemon $pkgname-daemon-openrc $pkgname-doc $pkgname-lang $pkgname-static"

# secfixes:
#   3.00-r0:
#     - CVE-2018-10756

build() {
	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=True \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DENABLE_GTK=TRUE \
		-DENABLE_CLI=TRUE \
		-DENABLE_TESTS=FALSE \
		-DWITH_SYSTEMD=FALSE \
		-DINSTALL_LIB=TRUE
	cmake --build build
}

package() {
	DESTDIR="$pkgdir" cmake --install build

	install -D -m755 "$srcdir"/transmission-daemon.initd \
		"$pkgdir"/etc/init.d/transmission-daemon
	install -D -m644 "$srcdir"/transmission-daemon.confd \
		"$pkgdir"/etc/conf.d/transmission-daemon
}

daemon() {
	pkgdesc="Lightweight BitTorrent client (daemon and webinterface)"

	install -d -o transmission -g transmission \
		"$subpkgdir"/var/lib/transmission \
		"$subpkgdir"/var/log/transmission
	amove usr/bin/transmission-daemon \
		usr/share/transmission
	install -D -m644 "$srcdir"/transmission-daemon.logrotate \
		"$subpkgdir"/etc/logrotate.d/transmission-daemon
}

cli() {
	pkgdesc="Lightweight BitTorrent client (cli and remote)"

	amove usr/bin/transmission-cli \
		usr/bin/transmission-create \
		usr/bin/transmission-edit \
		usr/bin/transmission-show \
		usr/bin/transmission-remote
}

sha512sums="
eeaf7fe46797326190008776a7fa641b6341c806b0f1684c2e7326c1284832a320440013e42a37acda9fd0ee5dca695f215d6263c8acb39188c5d9a836104a61  transmission-3.00.tar.xz
d31275fba7eb322510f9667e66a186d626889a6e3143be2923aae87b9c35c5cf0c508639f1cb8c1b88b1e465bc082d80bb1101385ebde736a34d4eeeae0f6e15  transmission-daemon.initd
dbc093fe00335bb207c28a4e810becc15e74b6f75e7579d561b160755d6b54bb23a45db39ee3480195a94a5e9bffdad692559d1b9662bba28119d18b713747a1  transmission-daemon.confd
a0e770a46b916cde7ea13076a0e4646c43f3b4db4bc85c18d2fee7cdb5cab458a74897ffb4bf66327f35ce145e89f5320460034a1392cc0df66aa1a3c0d82f7b  transmission-daemon.logrotate
a09db6628d618b75fe5688638256b87042987f3e3df2210a93ba0ddf5d7602150d28f2a9f85c1fbc7654b1e32be101871d24a466f2cccaf05b34abe07133edc9  disable-missing-lang.patch
dc7b0e06987b1e16fa6bfc1edb13fabe4a612a931628cf9bc872cef6985a9c4d83159da2386cc6ded7ae1d3dc2fa076076d9ffa98758d5ccefcdf27b4ccbf8c7  fix-gettext-sigsegv.patch
"
